package com.yipei.business.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yipei.business.domain.MlTodayProfit;
import com.yipei.business.service.IMlTodayProfitService;
import com.yipei.common.annotation.Log;
import com.yipei.common.core.controller.BaseController;
import com.yipei.common.core.domain.AjaxResult;
import com.yipei.common.core.page.TableDataInfo;
import com.yipei.common.enums.BusinessType;
import com.yipei.common.utils.SecurityUtils;
import com.yipei.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 今日利润Controller
 *
 * @author yipei
 * @date 2024-12-21
 */
@RestController
@RequestMapping("/business/profit")
@Api(tags = "今日利润", description = "今日利润")
public class MlTodayProfitController extends BaseController {
    @Autowired
    private IMlTodayProfitService mlTodayProfitService;

    /**
     * 查询今日利润列表
     */
    //@PreAuthorize("@ss.hasPermi('business:profit:list')")
    @ApiOperation("今日利润获取数据")
    @GetMapping("/list")
    public TableDataInfo list(MlTodayProfit mlTodayProfit) {
        startPage();
        List<MlTodayProfit> list = mlTodayProfitService.selectMlTodayProfitList(mlTodayProfit);
        return getDataTable(list);
    }

    /**
     * 导出今日利润列表
     */
    //@PreAuthorize("@ss.hasPermi('business:profit:export')")
    @ApiOperation("今日利润导出数据")
    @Log(title = "今日利润", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MlTodayProfit mlTodayProfit) {
        List<MlTodayProfit> list = mlTodayProfitService.selectMlTodayProfitList(mlTodayProfit);
        ExcelUtil<MlTodayProfit> util = new ExcelUtil<MlTodayProfit>(MlTodayProfit.class);
        util.exportExcel(response, list, "今日利润数据");
    }

    /**
     * 获取今日利润详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:profit:query')")
    @ApiOperation("今日利润通过ID获取数据")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mlTodayProfitService.selectMlTodayProfitById(id));
    }

    /**
     * 新增今日利润
     */
    //@PreAuthorize("@ss.hasPermi('business:profit:add')")
    @ApiOperation("今日利润新增数据")
    @Log(title = "今日利润", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MlTodayProfit mlTodayProfit) {
        return toAjax(mlTodayProfitService.insertMlTodayProfit(mlTodayProfit));
    }

    /**
     * 修改今日利润
     */
    //@PreAuthorize("@ss.hasPermi('business:profit:edit')")
    @ApiOperation("今日利润修改数据")
    @Log(title = "今日利润", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MlTodayProfit mlTodayProfit) {
        return toAjax(mlTodayProfitService.updateMlTodayProfit(mlTodayProfit));
    }

    /**
     * 删除今日利润
     */
    //@PreAuthorize("@ss.hasPermi('business:profit:remove')")
    @ApiOperation("今日利润删除数据")
    @Log(title = "今日利润", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mlTodayProfitService.deleteMlTodayProfitByIds(ids));
    }

    @ApiOperation("根据当前用户获取今日利润")
    @GetMapping("/tdAccListProfit")
    public AjaxResult tdAccListProfit(MlTodayProfit mlTodayProfit) {
        List<MlTodayProfit> list = mlTodayProfitService.tdAccListProfit(mlTodayProfit);
        return AjaxResult.success(list);
    }

}
